package com.taojin.shoppinginterest.pop;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.FragmentManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.taojin.shoppinginterest.R;

/**
 * Created by T400 on 15-5-14.
 */
public class PopHelper_findShop {
    private FragmentManager fm;
    private static PopHelper_findShop helper;
    private PopupWindow popupWindow;

    /**
     * 先考虑焦点
     *
     * @return
     */
    public static PopHelper_findShop getInstance() {
        if (helper == null) {
            helper = new PopHelper_findShop();
        }
        return helper;
    }



    private void init(Context context) {
        popupWindow = new PopupWindow(context);
        popupWindow.setBackgroundDrawable(new ColorDrawable(R.color.black));
    }

    /**
     * @param width
     * @param height
     */
    private void init(Context context, int width, int height) {
        this.init(context);
        popupWindow.setHeight(height);
        popupWindow.setWidth(width);
    }

    /**
     * @param width
     * @param height
     */

    public void init(Context context, View contentView, View anchor, int width, int height) {
        popupWindow = new PopupWindow(context);
        //设置popupwindow高度
        popupWindow.setHeight(height);
        //设置popupwindow宽度
        popupWindow.setWidth(width);
        popupWindow.setFocusable(true);
        //设置popupwindow的显示界面
        popupWindow.setBackgroundDrawable(new ColorDrawable(R.color.wheat) {
        });
        popupWindow.setOutsideTouchable(true);
        popupWindow.setContentView(contentView);

        popupWindow.showAtLocation(anchor, Gravity.BOTTOM, 0, anchor.getHeight());

    }

    public void init(Context context, View anchor) {
        this.init(context, createContentView(context), anchor, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    /**
     * 创建Popupwindow内容显示界面
     * @param context
     * @return
     */
    private View createContentView(final Context context) {
        LayoutInflater inflate = LayoutInflater.from(context);
        View contentView = inflate.inflate(R.layout.fragment_findshop_pop, null);
        ImageView imageView_shop = (ImageView) contentView.findViewById(R.id.shop);
        ImageView imageView_yule = (ImageView) contentView.findViewById(R.id.yule);
        ImageView imageView_gouwu = (ImageView) contentView.findViewById(R.id.gouwu);
        ImageView imageView_food = (ImageView) contentView.findViewById(R.id.food);
        imageView_food.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return contentView;
    }

//public void onClick(View v){
//    switch (v.getId()){
//        case R.id.shop:
//            Intent intent = new Intent();
//            intent.putExtra("aaa","1");
//            break;
//        case R.id.yule:
//            break;
//        case R.id.gouwu:
//            break;
//        case R.id.food:
//            break;
//    }
//}
    public void dismiss() {
        if (popupWindow != null) {
            popupWindow.dismiss();
        }
    }

    public boolean isShowing() {
        return popupWindow != null && popupWindow.isShowing() ? true : false;
    }

}
